const app = getApp();

Page({
  data: {
    rate: 1,

    avatarImg: app.getImgUrl('avatar.webp'),
    qrImg: app.getImgUrl('qr.png'),
    img: app.getImgUrl('image.webp'),
    z1: app.getImgUrl('z1.png'),
    z2: app.getImgUrl('z2.png'),
    z3: app.getImgUrl('z3.png'),
    isqiye: true,
    userdata: {
      avatar: ""
    }
  },
  godedit() {
    wx.navigateTo({
      url: '/pages/minemodule/personalData/personalData'
    })
  },
  async getperson() {
    //zzstatus  1企业用户，2客户
    if (app.globalData.session.zzstatus == 2) {
      this.setData({
        isqiye: false
      })
    } else {
      this.setData({
        isqiye: true
      })
    }

    let res = await app.axios(
      'user',
      {
        op: "ajaxUserSets",
        "zqstatus": app.globalData.session.zzstatus,
      },
      false
    )
    let items = res.item
    items.zzimgs = res.item.zzimgs.split(",")
    console.log(items.zzimgs)
    console.log(" items.zzimgs")
    items.phones = this.formatPhoneNumber(items.phone)
    this.setData({
      userdata: items
    })
    console.log(this.data.userdata)
  },
  formatPhoneNumber(phone) {
    // 先移除所有非数字字符
    const cleaned = phone.replace(/\D/g, '');

    // 检查是否是有效的11位手机号
    if (cleaned.length !== 11) return phone; // 如果不是11位，返回原值

    // 格式化为 3-4-4 格式
    return cleaned.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
  },
  onShow() {
    // 每次页面显示都会执行
    console.log('页面显示')
    this.getperson()
    // 这里适合做数据刷新等操作
  },
  onBack() {
    wx.navigateBack();
  },

  onChange(event) {
    this.setData({
      rate: event.detail,
    });
  },

  onContact() {
    // 打电话
    wx.makePhoneCall({
      phoneNumber: "13333333333",
    });
  },

  onAppointment() {
    wx.navigateTo({
      url: "/pages/client/fault_list/index",
    });
  },
});
